package com.zzs.team.Service;

import com.zzs.team.DAO.LikeDao;
import com.zzs.team.Entity.TeamShow;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LikeServiceImpl implements LikeService{

    @Autowired
    LikeDao likeDao;

    @Override
    public void addLike(String userID, Integer teamID) {
        likeDao.addLike(userID,teamID);
    }

    @Override
    public List<Integer> getUserLikes(String userID) {
        return likeDao.getUserLikes(userID);
    }

    @Override
    public void cancleLike(String userid, Integer teamid) {
        likeDao.cancleLike(userid,teamid);
    }

    /**
     * 用户点击进入我的收藏时的服务层接口
     * @param userID
     * @return 返回的是Teamshow的数组，所有都是用户收藏的，所以需要将TeamShow的like设为true
     */
    @Override
    public List<TeamShow> getUserLikesTeamShow(String userID) {
        List<TeamShow> likes = likeDao.getUserLikesTeamShow(userID);
        //消去用户的id
        for(TeamShow like:likes){
            like.setLike(true);
            like.setUserID(null);
            like.getUser().setOpenID(null);

        }
        return likes;
    }
}
